package practice_03;

import java.util.Scanner;

//数字字符串转罗马字符
//输入：0-9 字符串，不超过9位
//输出:对应罗马字符串:"",I,II,III,IV,V,VI,VII,VII,VIII,IX
public class ChangeToRoma {

    public static void change() {
        Scanner sc = new Scanner(System.in);
        String num;
        while (true) {
            System.out.println("请输入字符串(0-9):");
            num = sc.next();
            boolean flag = chick(num);
            if (flag) break;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < num.length(); i++) {
            int n = num.charAt(i) - 48;
            sb.append(ToRoma(n) + " ");
        }
        System.out.println(sb);
    }

    //    检查输入
    public static boolean chick(String s) {
        if (s.length() > 9) {
            return false;
        }
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) < '0' || s.charAt(i) > '9') {
                return false;
            }
        }
        return true;
    }

    public static String ToRoma(int num) {
        String[] Roma = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
        return Roma[num];
    }
}
